#include <iostream>

#include "psqt.h"

//psqt - piece on square scores used in movegen and eval

/*
the first set are used in the eval, the second set for intial move ordering

The values in the tables are a mix of values I have tried and tested, and used
from other programs.
*/

const int opp[144] = {
132,133,134,135,136,137,138,139,140,141,142,143,
120,121,122,123,124,125,126,127,128,129,130,131,
108,109,110,111,112,113,114,115,116,117,118,119,
96,97,98,99,100,101,102,103,104,105,106,107,
84,85,86,87,88,89,90,91,92,93,94,95,
72,73,74,75,76,77,78,79,80,81,82,83,
60,61,62,63,64,65,66,67,68,69,70,71,
48,49,50,51,52,53,54,55,56,57,58,59,
36,37,38,39,40,41,42,43,44,45,46,47,
24,25,26,27,28,29,30,31,32,33,34,35,
12,13,14,15,16,17,18,19,20,21,22,23,
0,1,2,3,4,5,6,7,8,9,10,11
};

const int Pawn[144] = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,-12,-8,-4,8,8,-4,-8,-12,0,0,
0,0,-12,-8,-4,10,10,-4,-8,-12,0,0,
0,0,-12,-8,-4,16,16,-4,-8,-12,0,0,
0,0,-12,-8,-4,8,8,-4,-8,-12,0,0,
0,0,-8,-4,0,12,12,0,-4,-8,0,0,
0,0,-6,-2,2,14,14,2,-2,-6,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};

const int Knight[144] = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,-47,-39,-35,-23,-23,-35,-39,-47,0,0,
0,0,-20,-12,-8,4,4,-8,-12,-20,0,0,
0,0,-12,-4,0,12,12,0,-4,-12,0,0,
0,0,-8,0,4,16,16,4,0,-8,0,0,
0,0,-8,0,4,16,16,4,0,-8,0,0,
0,0,-4,4,8,20,20,8,4,-4,0,0,
0,0,-12,-4,0,12,12,0,-4,-12,0,0,
0,0,-120,-20,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,0,2,2,0,-2,-4,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};


const int Rook[144] = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,-4,-2,0,2,2,0,-2,-4,0,0,
0,0,-4,-2,0,2,2,0,-2,-4,0,0,
0,0,-4,-2,0,2,2,0,-2,-4,0,0,
0,0,-4,-2,0,2,2,0,-2,-4,0,0,
0,0,-4,-2,0,2,2,0,-2,-4,0,0,
0,0,-4,-2,0,2,2,0,-2,-4,0,0,
0,0,-4,-2,0,2,2,0,-2,-4,0,0,
0,0,-4,-2,0,2,2,0,-2,-4,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};


const int eQueen[144] = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,-16,-12,-8,-4,-4,-8,-12,-16,0,0,
0,0,-12,-8,-4,0,0,-4,-8,-12,0,0,
0,0,-4,0,4,8,8,4,0,-4,0,0,
0,0,0,4,8,12,12,8,4,0,0,0,
0,0,0,4,8,12,12,8,4,0,0,0,
0,0,-4,0,4,8,8,4,0,-4,0,0,
0,0,-12,-8,-4,0,0,-4,-8,-12,0,0,
0,0,-16,-12,-8,-4,-4,-8,-12,-16,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};

const int KingMid[144] = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,24,28,16,12,12,16,28,24,0,0,
0,0,4,8,-4,-8,-8,-4,8,4,0,0,
0,0,-16,-12,-24,-28,-28,-24,-12,-16,0,0,
0,0,-36,-32,-44,-48,-48,-44,-32,-36,0,0,
0,0,-56,-52,-64,-68,-68,-64,-52,-56,0,0,
0,0,-76,-72,-84,-88,-88,-84,-72,-76,0,0,
0,0,-76,-72,-84,-88,-88,-84,-72,-76,0,0,
0,0,-76,-72,-84,-88,-88,-84,-72,-76,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};


const int KingEnd[144] = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,-32,-24,-12,0,0,-12,-24,-32,0,0,
0,0,-24,-16,-4,8,8,-4,-16,-24,0,0,
0,0,-12,-4,8,20,20,8,-4,-12,0,0,
0,0,0,8,20,32,32,20,8,0,0,0,
0,0,0,8,20,32,32,20,8,0,0,0,
0,0,-12,-4,8,20,20,8,-4,-12,0,0,
0,0,-24,-16,-4,8,8,-4,-16,-24,0,0,
0,0,-32,-24,-12,0,0,-12,-24,-32,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};


const int SupN[144]   = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,//1
0,0,0,0,0,0,0,0,0,0,0,0,//2
0,0,0,0,0,0,0,0,0,0,0,0,//3
0,0,0,0,0,0,0,0,0,0,0,0,//4
0,0,0,5,10,15,15,10,5,0,0,0,//5
0,0,0,7,15,20,20,15,7,0,0,0,//6
0,0,0,0,7,10,10,7,0,0,0,0,//7
0,0,0,0,0,0,0,0,0,0,0,0,//8
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
};
//  8 7 6 5 4 3 2 1

const int sqcol[144]   = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,0,1,0,1,0,1,0,0,//7
0,0,1,0,1,0,1,0,1,0,0,0,//8
0,0,0,1,0,1,0,1,0,1,0,0,//7
0,0,1,0,1,0,1,0,1,0,0,0,//8
0,0,0,1,0,1,0,1,0,1,0,0,//7
0,0,1,0,1,0,1,0,1,0,0,0,//8
0,0,0,1,0,1,0,1,0,1,0,0,//7
0,0,1,0,1,0,1,0,1,0,0,0,//8
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
};

/*
Set of piece square tables are using in the move generator
*/

int mBishop[144]   = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,2,5,5,5,5,2,0,0,0,
0,0,2,30,15,18,18,15,30,2,0,0,
0,0,5,15,30,20,20,30,15,5,0,0,
0,0,5,10,20,40,40,20,10,5,0,0,
0,0,5,10,20,40,40,20,10,5,0,0,
0,0,5,15,30,20,20,30,15,5,0,0,
0,0,2,30,15,18,18,15,30,2,0,0,
0,0,0,2,5,5,5,5,2,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
};
int mKnight[144] = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,2,5,5,5,5,2,0,0,0,
0,0,2,7,10,15,15,10,7,2,0,0,
0,0,5,10,18,20,20,18,10,5,0,0,
0,0,5,12,20,40,40,20,12,5,0,0,
0,0,5,12,20,40,40,20,12,5,0,0,
0,0,5,10,18,20,20,18,10,5,0,0,
0,0,2,7,10,15,15,10,7,2,0,0,
0,0,0,2,5,5,5,5,2,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
};
int mbRook[144]  = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,27,29,31,33,33,31,29,27,0,0,
0,0,27,29,31,33,33,31,29,27,0,0,
0,0,12,14,16,18,18,16,14,12,0,0,
0,0,0,2,3,4,4,3,2,0,0,0,
0,0,0,2,3,4,4,3,2,0,0,0,
0,0,0,2,3,4,4,3,2,0,0,0,
0,0,0,2,3,4,4,3,2,0,0,0,
0,0,5,7,9,11,11,9,7,5,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};
int mwRook[144]  = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,5,7,9,11,11,9,7,5,0,0,
0,0,0,2,3,4,4,3,2,0,0,0,
0,0,0,2,3,4,4,3,2,0,0,0,
0,0,0,2,3,4,4,3,2,0,0,0,
0,0,0,2,3,4,4,3,2,0,0,0,
0,0,12,14,16,18,18,16,14,12,0,0,
0,0,27,29,31,33,33,31,29,27,0,0,
0,0,27,29,31,33,33,31,29,27,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};

int mwQueen[144]  = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,3,4,5,6,6,5,4,3,0,0,
0,0,4,5,6,7,7,6,5,4,0,0,
0,0,5,6,7,8,8,7,6,5,0,0,
0,0,6,7,8,9,9,8,7,6,0,0,
0,0,7,8,9,10,10,9,8,7,0,0,
0,0,9,10,11,12,12,11,10,9,0,0,
0,0,16,17,18,19,19,18,17,16,0,0,
0,0,16,17,18,19,19,18,17,16,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};

int mbQueen[144]  = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,16,17,18,19,19,18,17,16,0,0,
0,0,16,17,18,19,19,18,17,16,0,0,
0,0,9,10,11,12,12,11,10,9,0,0,
0,0,7,8,9,10,10,9,8,7,0,0,
0,0,6,7,8,9,9,8,7,6,0,0,
0,0,5,6,7,8,8,7,6,5,0,0,
0,0,4,5,6,7,7,6,5,4,0,0,
0,0,3,4,5,6,6,5,4,3,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};

int mwKing[144]  = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,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,15,10,0,0,
0,0,5,10,30,40,40,30,10,5,0,0,
0,0,5,10,30,40,40,30,10,5,0,0,
0,0,5,10,15,15,15,15,10,5,0,0,
0,0,10,10,10,10,10,10,10,10,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};

int eKing[144]  = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,5,10,10,10,10,5,0,0,0,
0,0,5,15,20,20,20,20,15,5,0,0,
0,0,10,20,25,30,30,25,20,10,0,0,
0,0,10,20,30,40,40,30,20,10,0,0,
0,0,10,20,30,40,40,30,20,10,0,0,
0,0,10,20,25,30,30,25,20,10,0,0,
0,0,5,15,20,20,20,20,15,5,0,0,
0,0,0,10,10,10,10,10,5,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
};

 int ewPawn[144]  = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,5,10,15,20,20,15,10,5,0,0,
0,0,10,15,20,25,25,20,15,10,0,0,
0,0,15,20,25,30,30,25,20,15,0,0,
0,0,25,30,35,40,40,35,30,25,0,0,
0,0,40,45,50,55,55,50,45,40,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};

int ebPawn[144] = {
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,40,45,50,55,55,50,45,40,0,0,
0,0,25,30,35,40,40,35,30,25,0,0,
0,0,15,20,25,30,30,25,20,15,0,0,
0,0,10,15,20,25,25,20,15,10,0,0,
0,0,5,10,15,20,20,15,10,5,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};


const int *midtab[16] = {
    0,
    mwPawn, mbPawn,
    mKnight, mKnight,
    mBishop, mBishop,
    mwRook, mbRook,
    mwQueen, mbQueen,
    mwKing, mbKing,
    0,0,0
};

const int *endtab[16] = {
    0,
    ewPawn, ebPawn,
    mKnight, mKnight,
    mBishop, mBishop,
    mwRook, mbRook,
    mwQueen, mbQueen,
    eKing, eKing,
    0,0,0
};

